<?php

namespace Wgx\Admin\Com;

use PhpYes\Entity\BaseEntity;

class MenuBarMenuEntity extends BaseEntity
{
    /** @var null|array */
    private $childrenMap = null;

    /**
     * @inheritDoc
     */
    public function getConnName()
    {
        return \PhpYes\Apps::$p->adminToMenuDb()->getConnName();
    }

    /**
     * @inheritDoc
     */
    public function getDb($quoted = true)
    {
        return \PhpYes\Apps::$p->adminToMenuDb()->getDb($quoted);
    }

    /**
     * @inheritDoc
     */
    public function getTable($quoted = true)
    {
        return 'admin_menu';
    }

    /**
     * @return int|null
     */
    public function getPid()
    {
        return $this->get_('pid');
    }

    /**
     * @param MenuBarMenuEntity $childEntity
     */
    public function addChild($childEntity)
    {
        if (empty($childEntity)) {
            return;
        }
        if (empty($this->childrenMap)) {
            $this->childrenMap = array();
        }
        $this->childrenMap[intval($childEntity->getId())] = $childEntity;
    }

    /**
     * @param int $id
     */
    public function deleteChild($id)
    {
        if (empty($this->childrenMap)) {
            return;
        }
        $id = empty($id) ? 0 : intval($id);
        if (isset($this->childrenMap[$id])) {
            unset($this->childrenMap[$id]);
        }
    }

    /**
     * Children Map
     * [id1=>MenuBarMenuEntity1, id2=>MenuBarMenuEntity2, ...]
     * @return array|null
     */
    public function getChildrenMap()
    {
        return $this->childrenMap;
    }

    /**
     * @return int
     */
    public function getLevel()
    {
        return $this->get_('level');
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->get_('name');
    }

    /**
     * @return string|null
     */
    public function getPath()
    {
        return $this->get_('path');
    }

    /**
     * @return bool
     */
    public function getIsInMenubar()
    {
        return $this->get_('is_in_menubar');
    }

    /**
     * @return int
     */
    public function getPriority()
    {
        return $this->get_('priority');
    }

    /**
     * @return string|null
     */
    public function getIcon()
    {
        return $this->get_('icon');
    }

    /**
     * @return string|null
     */
    public function getIconColor()
    {
        return $this->get_('icon_color');
    }

    /**
     * @return string|null
     */
    public function getDefaultQuery()
    {
        return $this->get_('default_query');
    }
}